home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dmake / Localized-Source / cmdlist.c < prev    next >
Text File  |  1993-01-10  |  8KB  |  383 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from cmdlist.c
  3. */
  4.  
  5. /*
  6.  *  CMDLIST.c
  7.  *
  8.  */
  9.  
  10. #include "defs.h"
  11.  
  12. Prototype void InitCmdList(void);
  13. Prototype void PutCmdListChar(List *, char);
  14. Prototype void PutCmdListSym(List *, char *, short *);
  15. Prototype void CopyCmdList(List *, List *);
  16. Prototype void AppendCmdList(List *, List *);
  17. Prototype int  PopCmdListSym(List *, char *, long);
  18. Prototype int  PopCmdListChar(List *);
  19. Prototype void CopyCmdListBuf(List *, char *);
  20. Prototype void CopyCmdListNewLineBuf(List *, char *);
  21. Prototype long CmdListSize(List *);
  22. Prototype long CmdListSizeNewLine(List *);
  23. Prototype void CopyCmdListConvert(List *, List *, char *, char *);
  24. Prototype long ExecuteCmdList(DepNode *, List *);
  25.  
  26. List CmdFreeList;
  27. __aligned char CmdTmp1[256];
  28. __aligned char CmdTmp2[256];
  29.  
  30. void
  31. InitCmdList()
  32. {
  33.     NewList(&CmdFreeList);
  34. }
  35.  
  36. void
  37. PutCmdListChar(List *list, char c)
  38. {
  39.     CmdNode *node;
  40.  
  41.     if ((node = GetTail(list)) == NULL || (node->cn_Idx == node->cn_Max)) {
  42.     if ((node = RemHead(&CmdFreeList)) == NULL) {
  43.         node = malloc(sizeof(CmdNode) + 64);
  44.         node->cn_Node.ln_Name = (char *)(node + 1);
  45.         node->cn_Max = 64;
  46.     }
  47.     node->cn_Node.ln_Type = 0;
  48.     node->cn_Idx = 0;
  49.     node->cn_RIndex = 0;
  50.     AddTail(list, &node->cn_Node);
  51.     }
  52.     node->cn_Node.ln_Name[node->cn_Idx++] = c;
  53. }
  54.  
  55. void
  56. PutCmdListSym(list, buf, pspace)
  57. List *list;
  58. char *buf;
  59. short *pspace;
  60. {
  61.     if (*buf) {
  62.     if (pspace) {
  63.         if (*pspace)
  64.         PutCmdListChar(list, ' ');
  65.         *pspace = 1;
  66.     }
  67.     /*if ((node = GetTail(list)) && node->cn_Idx && node->cn_Node.ln_Name[node->cn_Idx-1] != ' ')*/
  68.     while (*buf) {
  69.         PutCmdListChar(list, *buf);
  70.         ++buf;
  71.     }
  72.     }
  73. }
  74.  
  75. void
  76. CopyCmdList(fromList, toList)
  77. List *fromList;
  78. List *toList;
  79. {
  80.     CmdNode *from;
  81.     long n;
  82.     long i;
  83.  
  84.     for (from = GetHead(fromList); from; from = GetSucc(&from->cn_Node)) {
  85.     CmdNode *copy = NULL;
  86.  
  87.     dbprintf(("COPYFROM %*.*s\n", from->cn_Idx, from->cn_Idx, from->cn_Node.ln_Name));
  88.  
  89.     for (n = 0; n < from->cn_Idx; ) {
  90.         if ((copy = RemHead(&CmdFreeList)) == NULL) {
  91.         copy = malloc(sizeof(CmdNode) + 64);
  92.         copy->cn_Max = 64;
  93.         copy->cn_Node.ln_Name = (char *)(copy + 1);
  94.         }
  95.         i = (copy->cn_Max < from->cn_Idx - n) ? copy->cn_Max : from->cn_Idx - n;
  96.         copy->cn_Node.ln_Type = 0;
  97.         copy->cn_Idx = i;
  98.         copy->cn_RIndex = 0;
  99.         movmem(from->cn_Node.ln_Name + n, copy->cn_Node.ln_Name, i);
  100.         AddTail(toList, ©->cn_Node);
  101.         n += i;
  102.     }
  103.     if (copy)
  104.         copy->cn_Node.ln_Type = from->cn_Node.ln_Type;
  105.     }
  106. }
  107.  
  108. void
  109. AppendCmdList(fromList, toList)
  110. List *fromList;
  111. List *toList;
  112. {
  113.     CmdNode *from;
  114.  
  115.     while (from = RemHead(fromList))
  116.     AddTail(toList, &from->cn_Node);
  117. }
  118.  
  119.  
  120. /*
  121.  *  pop a symbol (symbols are separated by white space)
  122.  */
  123.  
  124. int
  125. PopCmdListSym(cmdList, buf, max)
  126. List *cmdList;
  127. char *buf;
  128. long max;
  129. {
  130.     short c;
  131.     short i = 0;
  132.  
  133.     --max;
  134.  
  135.     while ((c = PopCmdListChar(cmdList)) == ' ' || c == '\t' || c == '\n')
  136.     ;
  137.     while (c != EOF && c != ' ' && c != '\t' && c != '\n' && i < max) {
  138.     buf[i++] = c;
  139.     c = PopCmdListChar(cmdList);
  140.     }
  141.     buf[i] = 0;
  142.     return((i) ? 0 : -1);
  143. }
  144.  
  145. int
  146. PopCmdListChar(cmdList)
  147. List *cmdList;
  148. {
  149.     CmdNode *node;
  150.     short c = EOF;
  151.  
  152.     while (node = GetHead(cmdList)) {
  153.     if (node->cn_RIndex != node->cn_Idx)
  154.         return((ubyte)node->cn_Node.ln_Name[node->cn_RIndex++]);
  155.     Remove((struct Node *)node);
  156.     AddTail(&CmdFreeList, &node->cn_Node);
  157.     }
  158.     return(c);
  159. }
  160.  
  161. void
  162. CopyCmdListBuf(list, buf)
  163. List *list;
  164. char *buf;
  165. {
  166.     CmdNode *node;
  167.     long n = 0;
  168.  
  169.     while (node = RemHead(list)) {
  170.     movmem(node->cn_Node.ln_Name + node->cn_RIndex, buf, node->cn_Idx - node->cn_RIndex);
  171.     buf += node->cn_Idx;
  172.     AddTail(&CmdFreeList, &node->cn_Node);
  173.     }
  174.     buf[0] = 0;
  175. }
  176.  
  177. void
  178. CopyCmdListNewLineBuf(list, buf)
  179. List *list;
  180. char *buf;
  181. {
  182.     CmdNode *node;
  183.     long i;
  184.  
  185.     while (node = RemHead(list)) {
  186.     for (i = node->cn_RIndex; i < node->cn_Idx && node->cn_Node.ln_Name[i] != '\n'; ++i)
  187.         *buf++ = node->cn_Node.ln_Name[i];
  188.     if (i != node->cn_Idx) {
  189.         node->cn_RIndex = i + 1;
  190.         AddHead(list, &node->cn_Node);
  191.         break;
  192.     }
  193.     AddTail(&CmdFreeList, &node->cn_Node);
  194.     }
  195.     *buf = 0;
  196. }
  197.  
  198. long
  199. CmdListSize(list)
  200. List *list;
  201. {
  202.     CmdNode *node;
  203.     long n = 0;
  204.  
  205.     for (node = GetHead(list); node; node = GetSucc(&node->cn_Node))
  206.     n += node->cn_Idx - node->cn_RIndex;
  207.     return(n);
  208. }
  209.  
  210. long
  211. CmdListSizeNewLine(list)
  212. List *list;
  213. {
  214.     CmdNode *node;
  215.     long n = 0;
  216.     long i;
  217.  
  218.     for (node = GetHead(list); node; node = GetSucc(&node->cn_Node)) {
  219.     for (i = node->cn_RIndex; i < node->cn_Idx && node->cn_Node.ln_Name[i] != '\n'; ++i)
  220.         ;
  221.     n += i - node->cn_RIndex;
  222.     if (i != node->cn_Idx)
  223.         break;
  224.     }
  225.     return(n);
  226. }
  227.  
  228. void
  229. CopyCmdListConvert(fromList, toList, srcMat, dstMat)
  230. List *fromList;
  231. List *toList;
  232. char *srcMat;
  233. char *dstMat;
  234. {
  235.     List tmpList;
  236.     short space = 0;
  237.  
  238.     dbprintf(("fromlist %08lx copyconvert '%s' -> '%s'\n", GetHead(fromList), srcMat, dstMat));
  239.     srcMat = ExpandVariable(srcMat, NULL);
  240.     dstMat = ExpandVariable(dstMat, NULL);
  241.  
  242.     NewList(&tmpList);
  243.     CopyCmdList(fromList, &tmpList);
  244.  
  245.     if (!*srcMat)
  246.     {
  247.        if (!GetHead(&tmpList))
  248.        {
  249.           PutCmdListSym(toList, dstMat, &space);
  250.           return;
  251.        }
  252.        /* We need to replace the src and destination with meaningful wildcards */
  253.        srcMat = dstMat = "*";
  254.     }
  255.  
  256.     /*
  257.      *    run each symbol through the conversion
  258.      */
  259.  
  260.     while (PopCmdListSym(&tmpList, CmdTmp1, sizeof(CmdTmp1)) == 0)
  261.     {
  262.     if (WildConvert(CmdTmp1, CmdTmp2, srcMat, dstMat) == 0)
  263.     {
  264.         PutCmdListSym(toList, CmdTmp2, &space);
  265.     }
  266.     }
  267. }
  268.  
  269. /*
  270.  *  The command list is executed by making a duplicate of it then reparsing
  271.  *  it resolving variable references
  272.  *
  273.  */
  274.  
  275. long
  276. ExecuteCmdList(dep, list)
  277. DepNode *dep;
  278. List *list;
  279. {
  280.     List tmpSrc;
  281.     List tmpDst;
  282.     short c;
  283.     long r = 0;
  284.  
  285.     NewList(&tmpSrc);
  286.     NewList(&tmpDst);
  287.     CopyCmdList(list, &tmpSrc);
  288.  
  289.     while ((c = PopCmdListChar(&tmpSrc)) != EOF) {
  290.     if (c == '$' || c == '%') {
  291.         short c0 = c;
  292.  
  293.         c = PopCmdListChar(&tmpSrc);
  294.         if (c == '(') {     /*  Variable Ref */
  295.         char *spec = AllocPathBuffer();
  296.  
  297.         /*
  298.          *  copy variable specification into a buffer then resolve
  299.          *  it to tmpDst
  300.          */
  301.         spec[0] = c0;
  302.         spec[1] = c;
  303.         for (c0 = 2; (c = PopCmdListChar(&tmpSrc)) != EOF && c != ')' && c0 < PBUFSIZE - 3; ++c0) {
  304.             if (c == '\"') {
  305.             spec[c0++] = c;
  306.             while ((c = PopCmdListChar(&tmpSrc)) != EOF && c != '\"' && c0 < PBUFSIZE - 3)
  307.                 spec[c0++] = c;
  308.             }
  309.             spec[c0] = c;
  310.         }
  311.         if (c != ')')
  312.             error(FATAL, "bad variable spec in command list for %s", dep->dn_Node.ln_Name);
  313.         spec[c0++] = c;
  314.         spec[c0] = 0;
  315.         ExpandVariable(spec, &tmpDst);
  316.         FreePathBuffer(spec);
  317.         continue;
  318.         }
  319.         if (c != c0)        /*  $$, %% escape   */
  320.         PutCmdListChar(&tmpDst, c0);
  321.     }
  322.     PutCmdListChar(&tmpDst, c);
  323.     }
  324.  
  325.   }
  326. ListChar(&tmget_string(MSG_0000,"bad variable spec in command list for %s"), dep->dn_Node.ln_Name);
  327.     /*
  328.      *    pop into a command buffer for execution
  329.      */
  330.  
  331.     {
  332.     long n;
  333.  
  334.     while (r <= 5 && (n = CmdListSizeNewLine(&tmpDst))) {
  335.         short allocated;
  336.         short quiet = 0;
  337.         short ignore= 0;
  338.         char *cmd;
  339.  
  340.         if (n >= sizeof(CmdTmp1) - 2) {    /*  avoid malloc    */
  341.         allocated = 1;
  342.         cmd = (char *)malloc(n + 2);
  343.         } else {
  344.         allocated = 0;
  345.         cmd = CmdTmp1;
  346.         }
  347.         while ((c = PopCmdListChar(&tmpDst)) != EOF && (c == ' ' || c == '\t'))
  348.         --n;
  349.         if (c == '@') {
  350.         quiet = 1;
  351.         c = PopCmdListChar(&tmpDst);
  352.         --n;
  353.         }
  354.         if (c == '-') {
  355.         ignore = 1;
  356.         c = PopCmdListChar(&tmpDst);
  357.         --n;
  358.         }
  359.         cmd[0] = c;
  360.         CopyCmdListNewLineBuf(&tmpDst, cmd + 1);
  361.  
  362.         if (c) {
  363.         cmd[n] = 0;
  364.  
  365.         if (quiet == 0)
  366.             printf("    %s\n", cmd);
  367.         if (NoRunOpt == 0 && cmd[0] != '#') {
  368.             r = Execute_Command(cmd, ignore);
  369.             if (r < 0)
  370.             r = 20;
  371.             if (ExitCode < r)
  372.             ExitCode = r;
  373.         }
  374.         }
  375.         if (allocated)
  376.         free(cmd);
  377.     }
  378.     }
  379. cmd);
  380. get_string(MSG_0001,"    %s\n")
  381.     return(r);
  382. }
  383.